import Vue from 'vue'
import Router from 'vue-router'

Router.prototype.goBack = function () {
  this.isBack = true
  this.back()
}
Vue.use(Router)
const Index = (resolve) => {
  import('views/index/index').then((module) => {
    resolve(module)
  })
}
const TopicDetail = (resolve) => {
  import('views/topic-detail/topic-detail').then((module) => {
    resolve(module)
  })
}
const Login = (resolve) => {
  import('views/login/login').then((module) => {
    resolve(module)
  })
}
const CreatTopic = (resolve) => {
  import('views/create-topic/create-topic').then((module) => {
    resolve(module)
  })
}
const User = (resolve) => {
  import('views/user/user').then((module) => {
    resolve(module)
  })
}
const MyCollect = (resolve) => {
  import('views/my-collect/my-collect').then((module) => {
    resolve(module)
  })
}
const Message = (resolve) => {
  import('views/message/message').then((module) => {
    resolve(module)
  })
}

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: Index
    },
    {
      path: '/topic-detail/:id',
      name: 'topic-detail',
      component: TopicDetail
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/create-topic',
      name: 'create-topic',
      component: CreatTopic
    },
    {
      path: '/user/:username',
      name: 'user',
      component: User
    },
    {
      path: '/my-collect',
      name: 'my-collect',
      component: MyCollect
    },
    {
      path: '/message',
      name: 'message',
      component: Message,
      children: [
        {
          path: ':state',
          name: 'childrenMessage',
          component: Message
        }
      ]
    }
  ]
})
